<template>
	<view class="container">
		<!-- 内容区域包装器 -->
		<view class="content-wrapper">
			<!-- 搜索区域 -->
			<view class="search-box">
				<u-search placeholder="请输入关键搜索" v-model="fromData.kw" :show-action="false" :clearabled="true"
					:animation="false" shape="round" bgColor="#F5F6FA" height="72rpx" searchIconColor="#999999"
					placeholderColor="#999999" @change="changekeword" :inputStyle="{
						color: '#333333',
						backgroundColor: '#F5F6FA',
					}"></u-search>
			</view>
		</view>
		<view class="content-box">
			<view class="content-list">
				<view v-if="showAll == '1'" class="content-item" @click="handleClick({id:'',address:'全部大楼'})">
						全部大楼
				</view>
				<view class="empty-review" v-if="list.length == 0 && showAll != '1'">
					<image src='../static/images/empty-review.png' mode="aspectFit"></image>
				</view>
				<view class="content-item" v-for="item in list" :key="item.id" @click="handleClick(item)">
						{{item.address}}
				</view>
			</view>
		</view>
	</view>
</template>


<script>
		import { addressList } from "@/api/landlord.js";
	export default {
		data() {
			return {
				fromData: {
					kw: ''
				},
				list: [],
				showAll:'0',
				timerId:null
			};
		},
		onLoad(options) {
			if(options.showAll) {
				this.showAll = options.showAll
			}
			this.init()
		},
		methods: {
			changekeword() {
				if (this.timerId) {
					clearInterval(this.timerId)
				}
				let that = this
				this.timerId = setTimeout(() => {
					that.init()
				}, 200)
			},
			init() {
				addressList(this.fromData).then(res => {
					console.log(res.data.data);
					this.list = res.data.data
				})
			},
			handleClick(template){
				console.log(template)
				uni.navigateBack({
						delta: 1,
						success: () => {
								// 通过事件或全局方式传参
								uni.$emit('buildingSelected', template);
						}
				});
			}
		},
	};
</script>

<style lang="less" scoped>
	.search-box {
		padding: 12rpx 20rpx 24rpx 32rpx;
		background-color: #fff;
	}

	.add-btn {
		padding: 20rpx;
	}

	.content-box {
		padding: 0 32rpx;
		padding-top: 20rpx;
	}

	.content-total {
		padding: 16rpx 0;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 22rpx;
		color: #999999;
	}

	.content-item {
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 0, 0, 0.01);
		border-radius: 24rpx;
		padding: 24rpx;
		margin-bottom: 24rpx;
	}

	.empty-review {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 48rpx 0;
	
		image {
			width: 328rpx;
			height: 208rpx;
			margin-bottom: 24rpx;
		}
	}
</style>